import time
from base.day12.wangzhe import os_tool as tool

from selenium import webdriver

tool.kill_process("chromedriver.exe")
# https://mail.qq.com/
driver = webdriver.Chrome()

driver.get('https://mail.qq.com/')
driver.switch_to.default_content()
# 策略1：直接定位到最里层的iframe  失败：不能直接定位最里部的
# id="ptlogin_iframe"
# iframe1 = driver.find_element_by_xpath('//iframe[@id="ptlogin_iframe"]')
# # 切换到最里部的iframe对应的html
# driver.switch_to_frame(iframe1)
# 策略2：先定位切换到外层iframe 再一步一步切换到内层所需要的iframe
iframe1 = driver.find_element_by_xpath('//div[@id="QQMailSdkTool_login_loginBox_qq"]/iframe')
print(iframe1, type(iframe1))
# 切换一次iframe对应的html
# driver.switch_to_frame(iframe1)
driver.switch_to.frame(iframe1)

# 定位到里部的iframe
iframe2 = driver.find_element_by_xpath('//iframe[@id="ptlogin_iframe"]')
# driver.switch_to_frame(iframe2)
driver.switch_to.frame(iframe2[0])

# 定位到密码登录的超链接 并点击
driver.find_element_by_xpath('//a[@id="switcher_plogin"]').click()

# 定位到账号输入框，并发送数据
driver.find_element_by_xpath('//input[@id="u"]').send_keys('xxxx')
# 定位到密码输入框，并发送数据
driver.find_element_by_xpath('//input[@id="p"]').send_keys('xxxx')

# 定位到登录按钮并点击
driver.find_element_by_xpath('//input[@id="login_button"]').click()

time.sleep(10)

driver.quit()
